﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using WMS.Pagination;

namespace WMS.BasicData.Categorys
{
    public class CategorysAppService:ApplicationService,ICategorysAppService
    {
        private readonly IRepository<Category,int> _categoryRepository;

        public CategorysAppService(IRepository<Category,int> categoryRepository)
        {
            _categoryRepository = categoryRepository;
        }

        public async Task<PageResult> GetListAsync(string? productName, int page, int limit)
        {
            var categorylist = await _categoryRepository.GetListAsync();

            categorylist = categorylist.WhereIf(!string.IsNullOrEmpty(productName), x => x.ProductName.Contains(productName)).ToList();
            PageResult pageResult = new PageResult();
            pageResult.RowCount = categorylist.Count();
            pageResult.PageCount = (int)Math.Ceiling(pageResult.RowCount * 1.0 / limit);
            pageResult.Queryable = categorylist.Skip((page - 1) * limit).Take(limit).AsQueryable();
            return pageResult;
        }
    }
}
